package com.xqgl.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xqgl.bean.User;
import com.xqgl.service.UserDaoImp;


/**
 * Servlet implementation class addUserServlet
 */
@WebServlet("/addUserServlet")
public class addUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;Charset=utf-8");
		String villagename = request.getParameter("villagename");
		String userhpro = request.getParameter("userhpro");
		String username = request.getParameter("username");
		String userpic = request.getParameter("userpic");
		int userid = Integer.parseInt(request.getParameter("userid"));
		int userphone = Integer.parseInt(request.getParameter("userphone"));
		String useroccupation = request.getParameter("useroccupation");
		String userbirth = request.getParameter("userbirth");
		String sex = request.getParameter("sex");
		String type = request.getParameter("type");
		String remark = request.getParameter("remark");
		String userctime = request.getParameter("userctime");
		User user = new User();
		user.setVillagename(villagename);
		user.setUserhpro(userhpro);
		user.setUsername(username);
		user.setUserpic(userpic);
		user.setUserid(userid);
		user.setUserphone(userphone);
		user.setUseroccupation(useroccupation);
		user.setUserbirth(userbirth);
		user.setSex(sex);
		user.setType(type);
		user.setRemark(remark);
		user.setUserctime(userctime);
		UserDaoImp imp = new UserDaoImp();
		try {
			imp.add(user);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect("userlist.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
